package com.woniuxy.bookmall.config;

import com.woniuxy.bookmall.intercepters.PermissionIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {
    @Autowired
    PermissionIntercepter permissionIntercepter ;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login.html").setViewName("login");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> list = new ArrayList<>();
        list.add("/asserts/**");
        list.add("/favicon.ico");
        list.add("/book/index");
        list.add("/book/showBook");
        list.add("/book/searchDetail");
        list.add("/user/login");
        list.add("/user/regView");
        list.add("/user/sendEmailCode");
        list.add("/user/validationEmail");
        list.add("/user/reg");
        list.add("/login.html");
        list.add("**/alipay/**");
        list.add("**/ali/**");
        registry.addInterceptor(permissionIntercepter)
                .addPathPatterns("/**")
                .excludePathPatterns(list);
    }
}
